package com.xuecheng.framework.domain.course.validator.coursebase;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class IsGradeValidator  implements ConstraintValidator<IsGrade, String> {
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (value == null || value.length() == 0) {
            return false;
        } else {
            return isGrade(value);
        }
    }

    public  boolean isGrade(String grade) {
        try{
            Integer.parseInt(grade);
        }catch (NumberFormatException e){
            return false;
        }
        return true;
    }
}
